#pragma once

#include <iostream>
#include <mutex>
#include <pthread.h>

class Mutex
{
public:
    Mutex()
    {
        pthread_mutex_init(&_lock, nullptr);
    }
    void Lock()
    {
        pthread_mutex_lock(&_lock);
    }
    void UnLock()
    {
        pthread_mutex_unlock(&_lock);
    }
    ~Mutex()
    {
        pthread_mutex_destroy(&_lock);
    }

    pthread_mutex_t *Get()
    {
        return &_lock;
    }
private:
    pthread_mutex_t _lock;
};

class LockGuard
{
public:
    LockGuard(Mutex *ptr) : _mutexptr(ptr)
    {
        _mutexptr->Lock();
    }
    ~LockGuard()
    {
        _mutexptr->UnLock();
    }

private:
    Mutex *_mutexptr;
};